package com.homevip.core.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import com.homevip.util.PropUtil;

/**
 * 全局变量
 * @author ll
 */
public class ThirdPart {

	public static String ServerInstance; // 服务实例编号
	
	public static String sms_debug; //短信开发模式
	
	public static String wx_debug;//微信开发模式
	public static String wx_local_server_token;//微信本地验证服务Token
	public static String wx_fwh_appid;//微信服务号应用ID (AppID)
	public static String wx_fwh_appsecret;//应用密钥 AppSecret (AppSecret)
	public static String wx_pay_appsecret;//支付密钥 AppSecret (AppSecret)
	public static String wx_fwh_mch_id;//商家号
	public static String wx_access_token_url;//通过code换取网页授权access_token
	public static String wx_refresh_token_url;//刷新access_token（如果需要）
	public static String wx_auth_token_rul;//检验授权凭证（access_token）是否有效
	public static String wx_userinfo_url;//拉取用户信息(需scope为 snsapi_userinfo)
	public static String wx_oauth_url;//微信开发平台验证地址
	public static String wx_api_token_url;//微信开发平台获取全局token
	public static String wx_ticket_url;//微信开发平台获取ticket地址
	public static String wx_unifiedorder_url;//微信开发平台下单地址
	public static String wx_pay_callback_url;//微信支付回调
	public static String wx_message_tpl;//消息模板id获取
	public static String wx_message_send;//消息推送
	
	public static String cc_auth_url; //CallCenter 验证地址
	public static String cc_auth_pwd; //CallCenter 验证密码
	
	public static String ems_enterpriseid; //易信通企业号
	public static String ems_name; //易信通用户名
	public static String ems_pwd; //易信通密码
	public static String ems_send_url; //易信通短信发送地址
	public static String ems_get_url;//易信通短信获取 
	
	/**
	 * 读取配置
	 * @throws IOException 
	 */
	public static boolean load() {
		
		String strFileName = "properties/thirdpart.properties";
		Properties ps = new Properties();
		FileInputStream istream = null;
		try {
			istream = new FileInputStream(PropUtil.getInstance().getSystemPath(strFileName));
			ps.load(istream);
			istream.close();
		} catch (Exception e) {
			return false;
		} finally {
			if (istream != null) {
				try {
					istream.close();
				} catch (Throwable ignore) {
				}
			}
		}
		
		ServerInstance = ps.getProperty("server_instance");
		if (null == ServerInstance) ServerInstance = "signle"; // 默认单例
		
		sms_debug = ps.getProperty("sms_debug");
		
		//weixin
		wx_debug = ps.getProperty("wx_debug");
		wx_local_server_token = ps.getProperty("wx_local_server_token");
		wx_fwh_appid = ps.getProperty("wx_fwh_appid");
		wx_fwh_appsecret = ps.getProperty("wx_fwh_appsecret");
		wx_pay_appsecret = ps.getProperty("wx_pay_appsecret");
		wx_fwh_mch_id = ps.getProperty("wx_fwh_mch_id");
		wx_access_token_url = ps.getProperty("wx_access_token_url");
		wx_refresh_token_url = ps.getProperty("wx_refresh_token_url");
	    wx_auth_token_rul = ps.getProperty("wx_auth_token_rul");
	    wx_userinfo_url = ps.getProperty("wx_userinfo_url");
	    wx_oauth_url = ps.getProperty("wx_oauth_url");
	    wx_api_token_url = ps.getProperty("wx_api_token_url");
	    wx_ticket_url = ps.getProperty("wx_ticket_url");
	    wx_unifiedorder_url = ps.getProperty("wx_unifiedorder_url");
	    wx_pay_callback_url = ps.getProperty("wx_pay_callback_url");
	    
	    wx_message_tpl = ps.getProperty("wx_message_tpl");
	    wx_message_send = ps.getProperty("wx_message_send");
		
	    //CallCenter
	    cc_auth_url = ps.getProperty("cc_auth_url");
	    cc_auth_pwd = ps.getProperty("cc_auth_pwd");
	    
	    //易信通
		ems_enterpriseid = ps.getProperty("ems_enterpriseid");
		ems_name = ps.getProperty("ems_name");
		ems_pwd = ps.getProperty("ems_pwd"); 
		ems_send_url = ps.getProperty("ems_send_url"); 
		ems_get_url = ps.getProperty("ems_get_url"); 
		
		return true;
	}
	
	/**
	 * 测试
	 * @param args
	 */
	public static void main(String[] args) {
		
		System.out.println("thirdparrt load...");
		ThirdPart.load();
		System.out.println("thirdparrt.wx_local_server_token: " + ThirdPart.wx_local_server_token);
	}
}
